package com.woniu.controller.config.interceptor;

import com.woniu.controller.config.interceptor.LoginInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * 自定义的配置类
 */
//@Configuration
public class MvcConfigM implements WebMvcConfigurer {
    @Autowired
    private LoginInterceptor loginInterceptor;
    /**
     * 注册拦截器
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // 放行的资源：登录、置换token、swagger
        List<String> whitelist = new ArrayList<>();
        Collections.addAll(whitelist,"/manager/login","/token/refresh",
                "/user/**","/**/druid/**","/swagger-resources/**","/swagger-ui.html/**");
        // 注册登录拦截器
        registry.addInterceptor(loginInterceptor)
                .addPathPatterns("/**")    // 拦截的资源，拦截所有
                .excludePathPatterns(whitelist);    // 放行的资源
    }
}